﻿@model IEnumerable<CloudFranceTriple.Models.PollSet>
@{
    var db = new CloudFranceTriple.Models.cloudfrAboq2RsDMEntities();
    var _userId = new CloudFranceTriple.WebRole.WebSecurityWrapper().CurrentUserId;
    Boolean ShowResults, HasPolled;
}
<section class="center">
    @if (Model.Count() == 0)
    {
    }
    else
    {
        <div class="center">
            @foreach (var item in Model)
            {
                ShowResults = (DateTime.Compare((item.CreationDatePoll.AddDays(item.DurationInDays)), DateTime.UtcNow) < 0);
                HasPolled = item.PollAnswerSet.Join(db.PollUserSet.Where(pu2 => pu2.UserId == _userId), answer => answer.Id, pu => pu.PollAnswer_Id, (anwser, pu) => anwser.Id).Count() > 0;
                         
                <div style="padding-bottom: 4px;" class="center">
                    <table style="border: 1px solid #fffffe; width: 300px;" class="center">
                        <tr>
                            <td>
                                @Html.HiddenFor(modelItem => item.OrderPoll)
                                <div class="poll-label">
                                    @CloudFranceTriple.WebRole.Properties.Resources.PollLabel
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <div class="poll-field">
                                    @Html.DisplayFor(modelItem => item.LabelPoll)
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td style="padding: 0; margin: 0;">
                                @Html.Action("Index", "PollAnswer", new { area = "Forum", id = item.Id })
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <div class="poll-label">
                                    @CloudFranceTriple.WebRole.Properties.Resources.PollDescription
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <div class="poll-field">
                                    @Html.DisplayTextFor(modelItem => item.DescriptionPoll)
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <div class="poll-label">
                                    @CloudFranceTriple.WebRole.Properties.Resources.PollCreationDate
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <div class="poll-field">
                                    @Html.DisplayFor(modelItem => item.CreationDatePoll, "TemplateUserDate")
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <div class="poll-label">
                                    @CloudFranceTriple.WebRole.Properties.Resources.PollUntilDate
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <div class="poll-field">
                                    @item.CreationDatePoll.AddDays(item.DurationInDays).ToShortDateString()
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <div class="poll-label">
                                    @CloudFranceTriple.WebRole.Properties.Resources.PollIsPublicPollResult
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <div class="poll-field">
                                    @Html.DisplayFor(model => item.IsPublicPollResult)
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <div class="poll-label">
                                    @CloudFranceTriple.WebRole.Properties.Resources.PollIsMemberOnlyPoll
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <div class="poll-field">
                                    @Html.DisplayFor(model => item.IsMemberOnlyPoll)
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                @if (ShowResults)
                                {
                                    @Html.ActionLink(CloudFranceTriple.WebRole.Properties.Resources.ButtonResults, "Results", "Poll", new { id = item.Id, area = "Forum" }, null)
                                }
                                @if (ViewBag.IsTopicAuthor && !HasPolled && !ShowResults)
                                {
                                    @Html.ActionLink(CloudFranceTriple.WebRole.Properties.Resources.ButtonEdit, "Edit", "Poll", new { id = item.Id, area = "Forum" }, null)
                                    @Html.ActionLink(CloudFranceTriple.WebRole.Properties.Resources.ButtonDelete, "Delete", "Poll", new { id = item.Id, area = "Forum" }, null)
                                }
                            </td>
                        </tr>
                    </table>
                </div>
            }
        </div>
        <br style="clear: left;" />
    }
    <p>
        @if (ViewBag.IsAuthor)
        {
            @Html.ActionLink(@CloudFranceTriple.WebRole.Properties.Resources.PollCreateBouton, "Create", "Poll", new { id = (ViewBag.Topic_Id as int?) ?? 0, area = "Forum" }, null)
        }
        @if (User.Identity.IsAuthenticated)
        {
            @Html.ActionLink(@CloudFranceTriple.WebRole.Properties.Resources.PollIndexTitle, "Index", "Poll", new { area = "Forum" }, null)
        }
    </p>
</section>
